﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Husb.Framework;
using Husb.Framework.DataAccess;
using System.ComponentModel;


namespace Crawler.Model
{
    [Serializable]
    public class TaskItemInfo :  EntityBase
    {
        #region Private Variables
        private System.Guid id;
        private System.Guid taskId;
        private System.String url;
        private System.Boolean? isNavigation;
        private System.Boolean? autoPaging;
        private System.Int32? pageCategory;
        private System.String nextPage;
        private System.Int32 maxPageCount;
        private System.String nextPageUrl;
        [NotUndoable]
        private TaskInfo task;
        //[NotUndoable]
        private BindingListView<CaptureRuleInfo> captureRules;
        #endregion

        #region Properties
        /// <summary>
        /// 
        /// </summary>		
        public System.Guid Id
        {
            get { return id; }
            set { id = value; }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.Guid TaskId
        {
            get { return taskId; }
            set { taskId = value; }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.String Url
        {
            get { return url; }
            set { url = value; }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.Boolean? IsNavigation
        {
            get { return isNavigation; }
            set { isNavigation = value; }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.Boolean? AutoPaging
        {
            get { return autoPaging; }
            set { autoPaging = value; }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.Int32? PageCategory
        {
            get { return pageCategory; }
            set { pageCategory = value; }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.Int32 MaxPageCount
        {
            get { return maxPageCount; }
            set { maxPageCount = value; }
        }
        /// <summary>
        /// 
        /// </summary>		
        public System.String NextPage
        {
            get { return nextPage; }
            set { nextPage = value; }
        }

        /// <summary>
        /// 
        /// </summary>		
        public System.String NextPageUrl
        {
            get { return nextPageUrl; }
            set { nextPageUrl = value; }
        }

        public TaskInfo Task
        {
            get
            {
                if (task == null)
                {
                    throw new NullReferenceException("此任务项所属的任务对象为空，不符合逻辑。");
                }
                return task;
            }
            set
            {
                task = value;
            }
        }

        public BindingListView<CaptureRuleInfo> CaptureRules
        {
            get
            {
                if (captureRules == null)
                {
                    captureRules = new BindingListView<CaptureRuleInfo>();
                    return captureRules;
                }
                else
                    return captureRules;
            }
            set
            {
                captureRules = value;
            }
        }

        #endregion

        #region GenerateFilterExpression
        /// <summary>
        /// 产生组合查询的条件
        /// </summary>
        /// <param name="taskItem">当前实体类<see cref="TaskItemInfo"/>TaskItemInfo</param>
        /// <returns></returns>
        public override string FilterExpression
        {
            get
            {
                string where = "";
                where += DataAccessHelper.GetPartWhereCondition("Id", Id);
                where += DataAccessHelper.GetPartWhereCondition("Url", Url);
                where += DataAccessHelper.GetPartWhereCondition("IsNavigation", IsNavigation);
                where += DataAccessHelper.GetPartWhereCondition("AutoPaging", AutoPaging);
                where += DataAccessHelper.GetPartWhereCondition("PageCategory", PageCategory);
                where += DataAccessHelper.GetPartWhereCondition("NextPage", NextPage);

                return where;
            }
        }
        #endregion

        #region Validate
        /// <summary>
        /// 数据验证
        /// </summary> 
        protected override void Validate()
        {
            //AddRule("Price", "Price must be greater than or equal to 0", this.Price < 0);
            AddRule("Url", "任务项的Url属性不能为空。", string.IsNullOrEmpty(this.Url));
        }
        #endregion
    }
}
